#include "InetAddress.h"

#include <arpa/inet.h>

InetAddress::InetAddress(uint16_t port,  std::string ip) {
    addr_.sin_family = AF_INET;
    addr_.sin_port = htons(port);
    addr_.sin_addr.s_addr = inet_addr(ip.c_str());
}

std::string InetAddress::toIp() const {
    char buff[64] = {0};
    // Use inet_ntoa to convert to string
    return std::string(inet_ntoa(addr_.sin_addr));
}
std::string InetAddress::toIpPort()const{
    return toIp() + ":" + std::to_string(toPort());
};

uint16_t InetAddress::toPort() const{
    return htobe16(addr_.sin_port);
};
